import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { getToken } from '@/utils/auth'



const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      children: [

        {
          path: '/user',
          name: 'user',
          component: () => import('../views/permission/user/index.vue'),
        },
        {
          path: '/role',
          name: 'role',
          component: () => import('../views/permission/role/index.vue'),
        },
        {
          path: '/menu',
          name: 'menu',
          component: () => import('../views/permission/menu/index.vue'),
        },

      ]
    },
    {
      path: '/login',
      name: 'login',

      component: () => import('../views/Login.vue'),
    },
  ],
})


const whitelist = ['/login']
// 全局路由守卫  当未登录并且访问的不是白名单的路径，需要切换到  login
// router.beforeEach((to, from, next) => {
//   const path = to.path;
//   const token = getToken()
//   if (token || whitelist.indexOf(path) != -1) {
//     console.log("已经登录");
//     next()
//   } else {
//     console.log("未登录");
//     next("/login")
//   }

// })



export default router
